<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>中心医院医疗服务系统</title>
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/icon.css"/>">
<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>

<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
</head>
<body>
<script src="<c:url value="/js/jquery-migrate-1.1.0.min.js"/>"></script>
	<script type="text/javascript" src="<c:url value="/js/jquery.jqprint-0.3.js"/>"></script>
<style>
	* {
		font-size: 12px;
	}
	
	.lmb-hc-item{
		margin-top: 5px;
	}
</style>
<script type="text/javascript">
	//获取当前登录用户的id
	var  shenpi_staffId = $("#tontyiStaffId").html();
	//查找出需要当前用户审批的采购计划
	$("#tb_lmbhcplansp").datagrid({
		url: "to_hsp_findByApprovepeople",
		queryParams:{
			spr: shenpi_staffId,
			page:1, 
			rows:10			
		}
	});



//日期转换
$(function(){
	function lmb_todate_hc_sp(value){
	    if(value){
			var date = new Date(value);  
	        return date.toLocaleDateString();
		}
	}

	$("#lmb_hc_plan_sp-add").linkbutton({onClick: function(){
		var rows = $("#tb_lmbhcplansp").datagrid("getSelections");
		if(rows.length == 1){	  
			$('#lmb-hc_plan_sp-win').window("open");
			var cpPlanId = rows[0].cpPlanId;
			$.getJSON("to_queryCurPurPlan", {"cpPlanId": cpPlanId}, function(data){
				$("#lmb-hcsp-cgjhbh").linkbutton({text: data.cpPlanId});
				$("#lmb-hcsp-xmmc").linkbutton({text: data.cpPlanTitle});
				$("#lmb-hcsp-zdr").linkbutton({text: data.mname});
				$("#lmb-hcsp-zdsj").linkbutton({text: lmb_todate_hc_sp(data.cpPlanDate)});
				$("#lmb-hcsp-spr").linkbutton({text: data.pname});
				$("#lmb-hcsp-spzt").linkbutton({text: data.cpPlanStatus});
				if(data.cpPlanStatus=='待审批' || data.cpPlanAppresult=='未通过'){
					$("#lmb-hcsp-spzt").css({'color': 'red'});
				}
				$("#lmb-hcsp-spsj").linkbutton({text: lmb_todate_hc_sp(data.cpPlanApprovedate)});
				$("#lmb-hcsp-cgzt").linkbutton({text: data.cpPlanPurstatus});
				if(data.cpPlanPurstatus=='未采购'){
					$("#lmb-hcsp-cgzt").css({'color': 'red'});
				}
			});	
			
			 //根据id查看详情	
			 $("#lmb-hcsp-dg").datagrid({
				url:'to_queryCurPurPlanDetailsByPage',
				width: '100%',
				queryParams:{					
	    			cpPlanId: cpPlanId,
	    			page:1, 
	    			rows:10
				}
			});
		}else{
			$.messager.alert("提示", "只能选择一条记录，您目前选择了" + rows.length + "条!");
		}
	}});
		
	$("#lmb—hcsp-btn-ok").linkbutton({onClick: function(){
		$.messager.prompt("提示", "备注", function(v){
			if(v){
				jg ='已通过';
				var rows = $("#tb_lmbhcplansp").datagrid("getSelections");
				var cpPlanId = rows[0].cpPlanId;
				
			
				$("#lmb-hc_plan_sp-form").form("submit", {
					url:'to_lmb_sp_hccgjh',
					queryParams:{
						id:cpPlanId,
						jg:jg,
						bz:v
					},
					success: function(v){
						$.messager.alert('提示', "审批成功！");
						//关闭窗口
						$('#lmb-hc_plan_sp-win').window('close');
						//重新加载数据lmb_hcx
						$("#tb_lmbhcplansp").datagrid("reload");	
					}				
				});
			}
		});
		
	}});
	
	$("#lmb—hcsp-btn-false").linkbutton({onClick: function(){
		$.messager.prompt("提示", "备注", function(v){
			if(v){
				jg ='未通过';
				var rows = $("#tb_lmbhcplansp").datagrid("getSelections");
				var cpPlanId = rows[0].cpPlanId;
				
			
				$("#lmb-hc_plan_sp-form").form("submit", {
					url:'to_lmb_sp_hccgjh',
					queryParams:{
						id:cpPlanId,
						jg:jg,
						bz:v
					},
					success: function(v){
						$.messager.alert('提示', "审批成功！");
						//关闭窗口
						$('#lmb-hc_plan_sp-win').window('close');
						//重新加载数据lmb_hcx
						$("#tb_lmbhcplansp").datagrid("reload");	
					}				
				});
			}
		});
		
	}});
	
	//查找已审批的采购计划
	 $("#lmb_hc_plan_sp-ysp").linkbutton({onClick: function(){
		 $("#tb_lmbhcplansp").datagrid({
				url:'to_queryByApprovepeopleYsp',
				method:'post',
				queryParams:{
					spr:shenpi_staffId,
			    	page:1, 
			    	rows:10
				}
			});
	 	}
	});
	
	//查找待审批的采购计划
	 $("#lmb_hc_plan_sp-dsp").linkbutton({onClick: function(){
		 $("#tb_lmbhcplansp").datagrid({
				url:'to_hsp_findByApprovepeople',
				method:'post',
				queryParams:{
					spr:shenpi_staffId,
			    	page:1, 
			    	rows:10
				}
			});
	 	}
	});
	
	//日期转换
	function lmb_todate_hcsp(value){
        if(value){
			var date = new Date(value);  
            return date.toLocaleDateString();
		}
    }
	
	//查看计划明细-打印
	$("#lmb_hc_plan_sp-xq").linkbutton({onClick: function(){
		var rows = $("#tb_lmbhcplansp").datagrid("getSelections");
		if(rows.length == 1){	  
			$('#lmb-hcjspDet-window').window("open");
			var cpPlanId = rows[0].cpPlanId;
			//<!--lmb-hcjDet-cgbh,lmb-hcjDet-xmmc,lmb-hcjDet-zdr, lmb-hcjDet-zdsj -->
			//<!--lmb-hcjDet-spr,lmb-hcjDet-spzt,lmb-hcjDet-spsj,lmb-hcjDet-cgzt  -->
			$.getJSON("to_queryCurPurPlan", {"cpPlanId": cpPlanId}, function(data){
				$("#lmb-hcjspDet-cgbh").linkbutton({text: data.cpPlanId});
				$("#lmb-hcjspDet-xmmc").linkbutton({text: data.cpPlanTitle});
				$("#lmb-hcjspDet-zdr").linkbutton({text: data.mname});
				$("#lmb-hcjspDet-zdsj").linkbutton({text: lmb_todate_hcsp(data.cpPlanDate)});
				$("#lmb-hcjspDet-spr").linkbutton({text: data.pname});
				$("#lmb-hcjspDet-spzt").linkbutton({text: data.cpPlanStatus});
				
				if(data.cpPlanAppresult=='已通过'){
					$("#lmb-hcjspDet-spzt").css({'color': 'green'});
				}else if(data.cpPlanAppresult=='未通过'){
					$("#lmb-hcjspDet-spzt").css({'color': 'red'});
				}
				$("#lmb-hcjspDet-spsj").linkbutton({text: lmb_todate_hcsp(data.cpPlanApprovedate)});
				$("#lmb-hcjspDet-cgzt").linkbutton({text: data.cpPlanPurstatus});
				if(data.cpPlanPurstatus=='未采购'){
					$("#lmb-hcjspDet-cgzt").css({'color': 'red'});
				}else if(data.cpPlanPurstatus=='已采购'){
					$("#lmb-hcjspDet-cgzt").css({'color': 'green'});
				}
			});	
			
			 //根据id查看详情	
			 $("#lmb-hcjspDet-dg").datagrid({
				url:'to_queryCurPurPlanDetailsByPage',
				width: '100%',
				queryParams:{					
	    			cpPlanId: cpPlanId,
	    			page:1, 
	    			rows:10
				}
			});
		}else{
			$.messager.alert("提示", "只能选择一条记录，您目前选择了" + rows.length + "条!");
		}
	}});
	
	//点击按钮打印
	$("#lmb-hcjspDet-print").linkbutton({
		onClick: function(){
			$("#lmb-hcjspDet-printArea").jqprint();
		}
	});
	
	// 刷新
	$("#lmb_hc_plan_sp-sx").linkbutton({onClick:function(){
		$("#tb_lmbhcplansp").datagrid({
    		url: 'to_hsp_findByApprovepeople', 
    		method: 'get'
    	});
	}});
});
	
</script>
<table id="tb_lmbhcplansp" class="easyui-datagrid" 
		data-options="	
			url:'to_hsp_findByApprovepeople',		
			fitColumns:true,fit:true,
			pagination: true,
			pageSize: 5,
			pageList: [5, 10, 15, 20],
			rownumbers: true,
			toolbar: '#tb_lmb_hc_plan_sp',
			border:false
			">
		<thead>
			<tr>	
				<th data-options="field:'',checkbox:true"></th>	
				<th data-options="field:'cpPlanId',width:'20%'">计划单号</th>								
				<th data-options="field:'cpPlanTitle',width:'15%'">项目名称</th>
				<th data-options="field:'mname',width:'15%'">制定人</th>
				<th data-options="field:'pname',width:'15%'">审批人</th>
				<th data-options="field:'cpPlanDate',width:'11%',
					formatter:function(value){
						if(value){
							var date = new Date(value);  
                            return date.toLocaleDateString();
						}                             
				}">制定时间</th>
				<th data-options="field:'cpPlanStatus',width:'11%'">审批状态</th>
				<th data-options="field:'cpPlanPurstatus',width:'11%'">采购状态</th>
			</tr>
		</thead>
	</table>
	
	<div id="tb_lmb_hc_plan_sp">
		<a id="lmb_hc_plan_sp-add" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">审批计划</a>
		<a id="lmb_hc_plan_sp-ysp" class="easyui-linkbutton" data-options="iconCls:'icon-ysp',plain:true">已审批计划</a>
		<a id="lmb_hc_plan_sp-dsp" class="easyui-linkbutton" data-options="iconCls:'icon-dsp',plain:true">待审批计划</a>
		<a id="lmb_hc_plan_sp-xq" class="easyui-linkbutton" data-options="iconCls:'icon-xiangqing',plain:true">计划详情</a>
	</div>
		
	<div id="lmb-hc_plan_sp-win" class="easyui-window" title="审核采购计划" data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,iconCls:'icon-save',closed: true" style="width:800px;height:500px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<form id="lmb-hc_plan_sp-form" method="post">	
					<table width="100%">
						<tr>
							<td>采购计划编号: <a id="lmb-hcsp-cgjhbh" name="cpPlanId"     class="easyui-linkbutton" data-options="plain:true,"></a></td>
							<td>项目名称: <a id="lmb-hcsp-xmmc" name="cpPlanTitle"  class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>制定人:  <a id="lmb-hcsp-zdr"  name="mname"        class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>制定时间: <a id="lmb-hcsp-zdsj" name="cpPlanDate"   class="easyui-linkbutton" data-options="plain:true"></a></td>
						</tr>
						<tr>
							<td>审批人:<a id="lmb-hcsp-spr" name="pname" class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>审批状态:<a id="lmb-hcsp-spzt" name="cpPlanStatus" class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>审批时间:<a id="lmb-hcsp-spsj" name="cpPlanApprovedate" class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>采购状态:<a id="lmb-hcsp-cgzt" name="cpPlanPurstatus" class="easyui-linkbutton" data-options="plain:true"></a></td> 
						</tr>
					</table>
						
					<div style="margin: 5px;">
						<table id="lmb-hcsp-dg" class="easyui-datagrid" 
							data-options="
								iconCls: 'icon-edit',
								singleSelect: true,										
								width: '100%'						
						">			
							<thead>
								<tr>	
									<th data-options="field:'cpdId',width:'20%',align:'center'">计划明细编号</th>	
									<th data-options="field:'cpdName',width:'21%',align:'center'">耗材名称</th>					
									<th data-options="field:'cpdNorms',width:'13%',align:'center'">单位</th>
									<th data-options="field:'cpdNum',width:'13%',align:'center'">数量</th>
									<th data-options="field:'gname',width:'21%',align:'center'">供应商</th>
									<th data-options="field:'cpdMoney',width:'13%',align:'center'">预计金额</th>
								</tr>
							</thead>
						</table>									
					</div>									
				</form>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a id="lmb—hcsp-btn-ok" class="easyui-linkbutton" data-options="iconCls:'icon-ok', plain:true" >PASS</a>
				<a id="lmb—hcsp-btn-false" class="easyui-linkbutton" data-options="iconCls:'icon-cancel', plain:true">PAIL</a>
			</div>
		</div>
	</div>	
	
	<!--查看详情窗口-打印 -->
	<div id="lmb-hcjspDet-window" class="easyui-window" title="采购计划详情" data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,iconCls:'icon-save',closed: true" style="width:70%;height:70%;">		
		<div class="easyui-layout" style="padding:0px;" data-options="fit:true">			
			<div id="lmb-hcjspDet-printArea" data-options="region:'center'" style="padding:5px;border-top:none;border-left:none;border-right:none;">			
				<form id="lmb_hcjspDet_form" method="post">
					<h1 style="text-align: center">耗材采购计划</h1>
					<table width="100%">
						<tr>
							<td>采购编号: <a id="lmb-hcjspDet-cgbh" name="cpPlanId"     class="easyui-linkbutton" data-options="plain:true,"></a></td>
							<td>项目名称: <a id="lmb-hcjspDet-xmmc" name="cpPlanTitle"  class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>制定人:  <a id="lmb-hcjspDet-zdr"  name="mname"        class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>制定时间: <a id="lmb-hcjspDet-zdsj" name="cpPlanDate"   class="easyui-linkbutton" data-options="plain:true"></a></td>
						</tr>
						<tr>
							<td>审批人:<a id="lmb-hcjspDet-spr" name="pname" class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>审批状态:<a id="lmb-hcjspDet-spzt" name="cpPlanStatus" class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>审批时间:<a id="lmb-hcjspDet-spsj" name="cpPlanApprovedate" class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>采购状态:<a id="lmb-hcjspDet-cgzt" name="cpPlanPurstatus" class="easyui-linkbutton" data-options="plain:true"></a></td>
						</tr>
					</table>
						
					<div style="margin: 5px;">
						<table id="lmb-hcjspDet-dg" class="easyui-datagrid" 
							data-options="
								iconCls: 'icon-edit',
								singleSelect: true,										
								width: '100%'						
						">			
							<thead>
								<tr>	
									<th data-options="field:'cpdId',width:'20%',align:'center'">计划明细编号</th>	
									<th data-options="field:'cpdName',width:'21%',align:'center'">药品名称</th>					
									<th data-options="field:'cpdNorms',width:'13%',align:'center'">单位</th>
									<th data-options="field:'cpdNum',width:'13%',align:'center'">数量</th>
									<th data-options="field:'gname',width:'21%',align:'center'">供应商</th>
									<th data-options="field:'cpdMoney',width:'13%',align:'center'">预计金额</th>
								</tr>
							</thead>
						</table>									
					</div>
				</form>				
			</div>
					
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a id="lmb-hcjspDet-print"  class="easyui-linkbutton" data-options="iconCls:'icon-print', plain:true">打印</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel', plain:true" href="javascript:$('#lmb-hcjspDet-window').window('close');">取消</a>
			</div>			
		</div>
	</div>
	
</body>
</html>